###类的多态：抽象基类

#导入抽象基类和抽象方法
from abc import ABC, abstractmethod
class Animal(ABC):
    @abstractmethod
    def speak(self):
        pass

class Dog(Animal):
    def speak(self):
        return "汪汪"

class Cat(Animal):
    def speak(self):
        return "喵喵"

# 尝试实例化抽象类会报错
# animal = Animal()  
# TypeError: Can't instantiate abstract class Animal with abstract method speak

# 使用抽象基类实现多态
def animal_sound(animal:Animal):
    print(animal.speak())

# 创建实例
dog = Dog()
cat = Cat()

animal_sound(dog)  # 汪汪
animal_sound(cat)  # 喵喵